package com.fcai.microserv.autoconfigure.jwt;

import com.fcai.microserv.jwt.FcaiJwtTokenManager;
import io.jsonwebtoken.JwtBuilder;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(JwtProperties.class)
@ConditionalOnClass(JwtBuilder.class)
@AllArgsConstructor
public class JwtConfiguration {
    private final JwtProperties jwtProperties;

    @Bean
    @ConditionalOnClass(JwtBuilder.class)
    public FcaiJwtTokenManager jwtTokenManager() {
        FcaiJwtTokenManager jwtTokenManager = new FcaiJwtTokenManager();
        jwtTokenManager.setActiveTime(jwtProperties.getActiveTime());
        jwtTokenManager.setSecretSalt(jwtProperties.getSecretSalt());
        jwtTokenManager.setHttpHeader(jwtProperties.getHttpHeader());
        return jwtTokenManager;
    }
}
